#include <stdio.h>
//#include <malloc.h>
#include <assert.h>
#include <stdlib.h>

int MAX_SIZE = 2048;

void access_counter (unsigned *hi, unsigned *lo);
double fun (int i);
void copyij (int **src, int **dst);

int main()
{
static unsigned cyc_hi1 = 0, cyc_hi2 = 0;
static unsigned cyc_lo1 = 0, cyc_lo2 = 0;

//int *test = NULL;

int **src = NULL, **dst = NULL;
int i = 0, j = 0;

src = (int**) calloc (MAX_SIZE, sizeof (int*)); assert (src != NULL);
dst = (int**) calloc (MAX_SIZE, sizeof (int*)); assert (dst != NULL);

for (i = 0; i < MAX_SIZE; i++)
	{
	src[i] = (int*) calloc (MAX_SIZE, sizeof (int)); assert (src[i] != NULL);
	dst[i] = (int*) calloc (MAX_SIZE, sizeof (int)); assert (dst[i] != NULL);
	}

access_counter (&cyc_hi1, &cyc_lo1);


copyij (src, dst);


access_counter (&cyc_hi2, &cyc_lo2);
printf ("%d, %d\n", cyc_hi2 - cyc_hi1, cyc_lo2 - cyc_lo1);

printf ("%d %d\n", src[5][10], dst[107][807]);

for (i = 0; i < MAX_SIZE; i++)
	{
	free (src[i]); src[i] = NULL;
	free (dst[i]); dst[i] = NULL;
	}
free (src); src = NULL;
free (dst); dst = NULL;


return 0;
}

void access_counter (unsigned *hi, unsigned *lo)
	{
    asm ("rdtsc; movl %%edx,%0; movl %%eax,%1"
		: "=r" (*hi), "=r" (*lo)
		:
		: "%edx", "%eax");
	}

double fun (int i)
	{
	volatile double d[1] = {3.14};
	volatile long int a[2];
	a[i] = 1073741824; /* Возможно за границами допустимого */
	return d[0];
	}

void copyij (int **src, int **dst)
	{
	int i = 0, j = 0;
	for (i = 0; i < MAX_SIZE; i++)
		for (j = 0; j < MAX_SIZE; j++)
		dst[i][j] = src[i][j];
	}
